package org.ccay.log.webtrace.impl; 

import org.ccay.core.log.CcayLoggerFactory;
import org.ccay.core.log.ILogger;
import org.ccay.core.util.StringUtil;

/**
 * 	Web Trace 状态监视器
 * @author chaowangbang
 * @since 2012-5-30
 */ 
public final class WebTraceStatusManager {
	private static final ILogger log = CcayLoggerFactory.getLogger(WebTraceStatusManager.class);
	private static final WebTraceStatusManager instance = new WebTraceStatusManager();
	/**
	 * 是否启用WebTrace
	 */
	public static boolean isWebTraceEnabled  = false; 
	
	/**
	 * 待跟踪的用户账号
	 */
	static String userAccount2Trace ;
	/**
	 * 避免实例
	 */
	private WebTraceStatusManager(){
	}
	
	/** 
	 * 获取唯一实例
	 * @return
	 */
	public static WebTraceStatusManager getInstance(){
		return instance;
	}
	/** 
	 * 开始Trace
	 * @param userAccount
	 * @param minutes
	 */
	public void beginTrace(String userAccount){
		log.info("Web Trace is enabled. For account: {0}", userAccount);
		if(!StringUtil.isNullOrEmpty(userAccount) && !"null".equals(userAccount)){
			userAccount2Trace = userAccount; 
		}
		isWebTraceEnabled=true;	
	}
	
	/**
	 * 结束Trace
	 */
	public void endTrace(){
		log.info("Web Trace is stopped.");
		isWebTraceEnabled=false;
		userAccount2Trace = null; 
	}
	
	

	/**
	 * @return the userAccount2Trace
	 */
	public String getUserAccount2Trace() {
		return userAccount2Trace;
	}

	/**
	 * @param userAccount2Trace the userAccount2Trace to set
	 */
	public void setUserAccount2Trace(String userAccount2Trace) {
		WebTraceStatusManager.userAccount2Trace = userAccount2Trace;
	}
 

	/**
	 * @return the isWebTraceEnabled
	 */
	public boolean isWebTraceEnabled() {
		return isWebTraceEnabled;
	}

	/**
	 * @param isWebTraceEnabled the isWebTraceEnabled to set
	 */
	public void setWebTraceEnabled(boolean isWebTraceEnabled) {
		WebTraceStatusManager.isWebTraceEnabled = isWebTraceEnabled;
	}
 
}
